// import { type RouteObject, createBrowserRouter } from 'react-router-dom'
import { type RouteObject, createBrowserRouter, Navigate } from 'react-router'
import { lazy } from 'react'
import {
  TeamOutlined,
  ApartmentOutlined,
  MenuOutlined,
  BookOutlined,
  HomeOutlined,
  UserOutlined
} from '@ant-design/icons'

import Layout from '@/layout'
import AuthGuard from '@/components/authGuard'

const Home = lazy(() => import('@/page/home'))
const Login = lazy(() => import('@/page/login'))
const NotFoundPage = lazy(() => import('@/page/404'))
const User = lazy(() => import('@/page/system/user'))
const Role = lazy(() => import('@/page/system/role'))
const Dept = lazy(() => import('@/page/system/dept'))
const Menu = lazy(() => import('@/page/system/menu'))
const Dict = lazy(() => import('@/page/system/dict'))
const Position = lazy(() => import('@/page/system/position'))

// 导出图标供侧边栏使用
export const SystemIcons = {
  user: UserOutlined, // 用户管理
  role: TeamOutlined, // 角色管理
  dept: ApartmentOutlined, // 部门管理
  menu: MenuOutlined, // 菜单管理
  dict: BookOutlined // 字典管理
}
const routers: RouteObject[] = [
  {
    path: '/',
    element: (
      <AuthGuard>
        <Layout />
      </AuthGuard>
    ),
    children: [
      {
        index: true,
        element: <Navigate to='/home' replace />
      },
      {
        path: 'home',
        element: <Home />
      },
      {
        path: 'system',
        children: [
          {
            path: 'user',
            element: <User />
          },
          {
            path: 'role',
            element: <Role />
          },
          {
            path: 'dept',
            element: <Dept />
          },
          {
            path: 'menu',
            element: <Menu />
          },
          {
            path: 'dict',
            element: <Dict />
          },
          {
            path: 'dictData',
            element: <Dict />
          },
          {
            path: 'position',
            element: <Position />
          }
        ]
      }
    ]
  },
  {
    path: '/login',
    element: <Login />
  },
  {
    path: '/404',
    element: <NotFoundPage />
  },
  {
    path: '*',
    element: <NotFoundPage />
  }
]

export default createBrowserRouter(routers)
